﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using Eassets.Service.Global;
using Eassets.Layered.Domain.Global;
using Eassets.Service.Asset;
using System.Collections.ObjectModel;
using Eassets.Layered.Domain.Asset;

namespace Eassets.UI.Asset
{
    public partial class AssetDepreciationForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetOrganizationLevelList();
            }
        }

        private void GetOrganizationLevelList()
        {
            OrganizationLevelListService organizationLevelListService = new OrganizationLevelListService();
            List<OrganizationLevelList> organizationLevelLists = new List<OrganizationLevelList>();
            organizationLevelLists = organizationLevelListService.GetAllOrganizationLevelList().Where(x => x.OrganizationLevelMode == "B").ToList();
            dropDownListOrganizationLevelList.DataSource = organizationLevelLists;
            dropDownListOrganizationLevelList.DataValueField = "OrganizationLevelListId";
            dropDownListOrganizationLevelList.DataTextField = "Code";
            dropDownListOrganizationLevelList.DataBind();
        }

        private void GetAssetItemDetailsByOrganizationLevelListId()
        {
            AssetItemDetailsService AssetItemDetailService = new AssetItemDetailsService();
            Collection<AssetItemDetails> assetItemDetails = new Collection<AssetItemDetails>();
            AssetItemDetails assetItemDetail = new AssetItemDetails();
            assetItemDetail.OrganizationLevelListId = Convert.ToInt64(dropDownListOrganizationLevelList.SelectedValue);
            assetItemDetail.AssetId = 0;
            assetItemDetails = AssetItemDetailService.GetAllAssetItemDetailsByOrganizationLevelListId(assetItemDetail.OrganizationLevelListId, assetItemDetail.AssetId);
            gridViewAssetDetails.DataSource = assetItemDetails.ToList();
            gridViewAssetDetails.DataBind();
        }

        protected void dropDownListOrganizationLevelList_SelectedIndexChanged(object sender, EventArgs e) 
        {
             GetAssetItemDetailsByOrganizationLevelListId();
        }

        protected void buttonView_OnClick(object sender, EventArgs e) 
        {
           
        }

        protected void buttonConfirm_OnClick(object sender, EventArgs e) 
        {
           
        }

    }
}